﻿// Study0626.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第六章 数组和指针 实验
//编写矩阵转置函数，输入参数为3X3整型数组
//编写main（）函数实现输入输出

#include <iostream>
using namespace std;
int** transposition(int** a) 
{
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			const int temp= a[j][i];
			a[j][i] = a[i][j];
			a[i][j] = temp;

		}
	}
	return a;
}

int main()
{
	int** p;
	p = new int* [3];
	for (int i = 0; i < 3; ++i)
	{
		p[i] = new int[3];
	}
	cout << "输入3X3整型数组元素：" << endl;
	for (int m = 0; m < 3; ++m)
	{
		for (int n = 0; n < 3; ++n)
		{
			cin >> p[m][n];
		}
	}
	cout << "初始数组为：" << endl;
	for (int m = 0; m < 3; ++m)
	{
		for (int n = 0; n < 3; ++n)
		{
			cout<< p[m][n] << "\t";
		}
		cout << endl;
	}
	p = transposition(p);
	cout << "转置数组后为：" << endl;
	for (int m = 0; m < 3; ++m)
	{
		for (int n = 0; n < 3; ++n)
		{
			cout << p[m][n]<<"\t";
		}
		cout << endl;
	}

	delete[] p;
	return 0;
}


